<?php
$this->LoadHelper('ApiHelper');
$ApiHelper = new ApiHelper();

$this->LoadHelper('MemberHelper');
$MemberHelper = new MemberHelper();

$this->LoadHelper('OrderHelper');
$OrderHelper = new OrderHelper();

$this->LoadResurces('oldapi/class.carloan');
$carloan = new Carloan();

$check = $ApiHelper->tokenCheck($this->Param);
if(!$check['success']) ErrorMsg::ApiMsg($check['msg'], $check['code']);

if (empty($this->Param['option'])) {    
    
} else {
    switch ($this->Param['option']){
        case 'orderdue':
            $oid = empty($this->Param['oid']) ? ErrorMsg::ApiMsg('参数错误') : $this->Param['oid'];
            $page = isset($this->Param['page']) ? $this->Param['page'] : 1;
            $rp = isset($this->Param['rp']) ? $this->Param['rp'] : PAGE_SIZE;
            //检测订单是否为权限允许内操作
            $order_check = $OrderHelper->checkOrderper($oid, $this->Param['uid']);
            if(!$order_check['success'])                ErrorMsg::ApiMsg ('无权操作', 20000);
            $order = $OrderHelper->orderRow($oid);
            //$result = $carloan->overdue($order['o_number'], $page, $rp);
            $result = $carloan->overdue('浙B01-151026-013', $page, $rp);
            $result = json_decode($result, TRUE);
            $json_data = array('total' => $result['data']['total'], 'list' => array(), 'page' => $page, 'pagetotal' => ceil($result['data']['total']/$rp));
            if (!empty($result['data']['root'])){
                foreach ($result['data']['root'] AS $rowNum => $row) {
                    $json_data['list'][] = $row;
                }
            }
            $ApiHelper->logSave('interface_orderdue', $this->Param);
            ErrorMsg::ApiMsg('请求成功', 0, $json_data);
            break;
        case 'dept':
            $oid = empty($this->Param['oid']) ? ErrorMsg::ApiMsg('参数错误') : $this->Param['oid'];
            $page = isset($this->Param['page']) ? $this->Param['page'] : 1;
            $rp = isset($this->Param['rp']) ? $this->Param['rp'] : PAGE_SIZE;
            //检测订单是否为权限允许内操作
            $order_check = $OrderHelper->checkOrderper($oid, $this->Param['uid']);
            if(!$order_check['success'])                ErrorMsg::ApiMsg ('无权操作', 20000);
            $order = $OrderHelper->orderRow($oid);
            //$result = $carloan->dept($order['o_number'], $page, $rp);
            $result = $carloan->dept('浙D01-150914-003', $page, $rp);
            $result = json_decode($result, TRUE);
            $json_data = array('total' => $result['data']['total'], 'list' => array(), 'page' => $page, 'pagetotal' => ceil($result['data']['total']/$rp));
            if (!empty($result['data']['root'])){
                foreach ($result['data']['root'] AS $rowNum => $row) {
                    $json_data['list'][] = $row;
                }
            }
            $ApiHelper->logSave('interface_dept', $this->Param);
            ErrorMsg::ApiMsg('请求成功', 0, $json_data);
            break;
        case 'afloan':
            $oid = empty($this->Param['oid']) ? ErrorMsg::ApiMsg('参数错误') : $this->Param['oid'];
            //检测订单是否为权限允许内操作
            $order_check = $OrderHelper->checkOrderper($oid, $this->Param['uid']);
            if(!$order_check['success'])                ErrorMsg::ApiMsg ('无权操作', 20000);
            $order = $OrderHelper->orderRow($oid);
            //$result = $carloan->post_loan($order['o_number'], $page, $rp);
            $result = $carloan->post_loan('浙B03-150526-001', $page, $rp);
            $result = json_decode($result, TRUE);
            $json_data = array(
                'cardinfo' => array(
                    'mp_credit_no' => $result['data']['mp_credit_no'], //贷记卡号
                    'mp_pack_add' => $result['data']['mp_pack_add'], //卡片送寄地址
                    'mp_pack_time' => $result['data']['mp_pack_time'], //还款卡片寄出日期
                    'mp_repay_gettime' => $result['data']['mp_repay_gettime'] //卡片收到日期
                ),
                'lending' => array(
                    'mp_adtime' => $result['data']['mp_adtime'], //公司垫付日期
                    'mp_pact_totime' => $result['data']['mp_pact_totime'], //合同送交银行日期
                    'mp_cprice_date' => $result['data']['mp_cprice_date'], //车资到达日期
                    'mp_reg_godate' => $result['data']['mp_reg_godate'], //登记证书到达日期
                    'mp_bank_time' => $result['data']['mp_bank_time'] //银行放贷日期
                ),
                'pledge' => array(
                    'mp_pledge_towgdate' => $result['data']['mp_pledge_towgdate'], //抵押资料寄网点日期
                    'mp_dl_date' => $result['data']['mp_dl_date'] //抵押办理日期
                ),
            );
            $ApiHelper->logSave('interface_afloan', $this->Param);
            ErrorMsg::ApiMsg('请求成功', 0, $json_data);
            break;
    }
}